/*
* @Author: Choisaaaa
* @Date: 2018/5/4  15:49
* 图片上传子组件
* NPM逛网介绍 https://www.npmjs.com/package/react-fileupload
*/

import "./index.scss"
import React from 'react';
import FileUpload from './react-fileupload.jsx';

class FileUploader extends React.Component{
    constructor(props){
        super(props);
        this.state = {
            maxFiles : this.props.maxFiles,
            fileFieldName : this.props.fileFieldName
        }
    }
    render(){
        var numberLimit = parseInt(this.state.maxFiles) || false;
        var fileFieldName = this.state.fileFieldName || "upload_file"
        const options={
            /*baseUrl         :'/image/upload.do',  本地测试用，结合配置文件的代理使用*/
            baseUrl         :'http://www.choisaaaa.shop/image/upload.do',
            fileFieldName   : fileFieldName,
            dataType        : 'json',
            numberLimit : numberLimit,
            chooseAndUpload : true,
            uploadSuccess   : (res) => {
                this.props.onSuccess(res.data);
            },
            uploadError     : (err) => {
                this.props.onError(err.message || '上传图片出错啦');
            }
        }
        return (
            <FileUpload options={options}>
                <button ref="chooseAndUpload" className="chooseAndUpload"><i className="fa fa-image"></i> Choose And Upload</button>
            </FileUpload>
        )
    }
}
export default FileUploader;